/**
 * 右侧导航
 */
define(function (require) {
    'use strict';
    var $ = require('jquery');
    var environment = require('environment');
    var NavManager = require('/static_public/public_menu/navManager');
    require('/static_public/js/token');

    function getMapData(gameMap) {
        return [
            {
                'id': 'menu_home',
                'code': '',
                'name': '首页',
                'level': 1,
                'iconCls': 'icon-home',
                'url': ['/page/app_store/index.shtml'],
                'children': null
            },
            {
                'id': 'menu_hdyx',
                'code': '',
                'name': '互动游戏',
                'level': 1,
                'iconCls': 'icon-game',
                'url': '',
                'cls': 'icon-fav',
                'children': gameMap
            },
            {
                'id': 'menu_020_3',
                'code': '500901',
                'name': '微楼书（新版）',
                'level': 1,
                'iconCls': 'icon-new-wls',
                'cls': 'c-mvp not-mvp icon-fav',
                'url': '',
                'children': [
                    {
                        'id': 'wls_lsgl',
                        'code': '500901',
                        'name': '楼书管理',
                        'level': 2,
                        'target': '_blank',
                        'url': [environment.wls + '/wls/index.html#/loushu/list']
                    },
                    {
                        'id': 'wls_lpgl',
                        'code': '500902',
                        'name': '楼盘管理',
                        'level': 2,
                        'target': '_blank',
                        'url': [environment.wls + '/wls/index.html#/building/list']
                    },
                    {
                        'id': 'wls_hdgl',
                        'code': '500903',
                        'name': '活动管理',
                        'level': 2,
                        'target': '_blank',
                        'url': [environment.wls + '/wls/index.html#/party/list']
                    }
                ]
            },
            {
                'id': 'menu_020_4',
                'code': '500101',
                'name': '微楼书（旧版）',
                'level': 1,
                'iconCls': 'icon-old-wls',
                'cls': 'c-mvp not-mvp',
                'target': '_blank',
                'url': ['/api/index.php?r=site/redirect-to&page=wls1']
            },
            {
                'id': 'menu_qita',
                'code': '',
                'name': '其他应用',
                'level': 1,
                'iconCls': 'icon-application',
                'url': '',
                'cls': 'icon-fav',
                'children': [
                    {
                        'id': 'menu_020_6',
                        'code': '50040202',
                        'name': '一键拨号',
                        'level': 2,
                        'iconCls': 'icon-app-store-yjbh',
                        'url': ['/page/o2o_application/speed_dial.shtml']
                    },
                    {
                        'id': 'menu_020_7',
                        'code': '50040201',
                        'name': '税费计算器',
                        'level': 2,
                        'iconCls': 'icon-app-store-sfjs',
                        'url': ['/page/o2o_application/tax_calculator.shtml']
                    },
                    {
                        'id': 'menu_020_8',
                        'code': '50040204',
                        'name': '360全景相册',
                        'level': 2,
                        'iconCls': 'icon-app-store-album360',
                        'url': ['/page/o2o_application/album360.shtml', '/page/o2o_application/album360-edit.shtml']
                    },
                    {
                        'id': 'menu_020_9',
                        'code': '50040203',
                        'name': '普通相册',
                        'level': 2,
                        'iconCls': 'icon-app-store-album',
                        'url': ['/page/o2o_application/album.shtml']
                    }
                ]
            }

        ];
    }

    return {
        init: function () {
            var navManager = new NavManager($('#nav'), getMapData([]));

            $.ajax({
                url: environment.wls + '/index.php?r=act/act/get-party-list-conf',
                cache: false,
                dataType: 'jsonp',
                jsonp: 'callback',
                success: function (data) {
                    if (data.retCode == 0) {
                        if (data.partyList && data.partyList.list) {
                            var gameMap = [];

                            var list = data.partyList.list;

                            var item;
                            for (var i = 0; item = list[i]; i++) {
                                gameMap.push({
                                    'id': 'menu_game_' + item.gameType,
                                    'code': '50040102',
                                    'name': item.gameTitle,
                                    'level': 2,
                                    'target': '_blank',
                                    'url': [environment.wls + '/wls/index.html#/' + item.gameUrl]
                                })
                            }

                            navManager.setMapData(getMapData(gameMap));
                        }
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                },
                timeout: 10000
            });
        }
    };
});
